import 'package:flutter/material.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/custom_password_field.dart';
import 'package:ytbusiness/widgets/widgets.dart';

///再次设置密码
class AgainSetPassword extends StatefulWidget {
  @override
  _AgainSetPasswordState createState() => _AgainSetPasswordState();
}

class _AgainSetPasswordState extends State<AgainSetPassword> {
  List<String> keyboard = ["1","2","3","4","5","6","4","8","9"];//键盘
  String passWord = "";// 密码
  bool keyIsShow = false;//显示隐藏键盘
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: customAppBar(context,title: "设置支付密码",elevation: setWidth(0.5)),
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              margin: EdgeInsets.only(top: setWidth(42)),
              alignment: Alignment.center,
              child: Text("请再次输入",style: TextStyle(color: Color(0xff323232),fontSize: setSp(18),fontWeight: FontWeight.w600),),
            ),
            Container(
              margin: EdgeInsets.only(top: setWidth(57)),
              height: setWidth(44),
              width: setWidth(345),
              child: CustomPasswordField(passWord),
            ),
            Container(
              margin: EdgeInsets.only(top: setWidth(22),left: setWidth(10),right: setWidth(10)),
              height: setWidth(50),
              decoration: BoxDecoration(
                color: passWord.length == 6  ?Color(0xff00C65F):Color.fromARGB(76, 0, 198, 95),
                borderRadius: BorderRadius.circular(4)
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text("下一步",style: TextStyle(color: Colors.white,fontSize: setSp(16)),),
                ],
              ),
            ),
          ],
        ),
      ),
      bottomSheet: Container(
        child: ListView(
          physics: NeverScrollableScrollPhysics(),
          shrinkWrap: true,
          children: [
            //显示隐藏键盘
            GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: (){
                setState(() {
                  keyIsShow = !keyIsShow;
                });
              },
              child: Container(
                padding: EdgeInsets.only(top: setWidth(17),bottom: setWidth(17)),
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(top: BorderSide(width: setWidth(0.5),color: Color(0xffF5F5F5)),
                        bottom: BorderSide(width: setWidth(0.5),color: Color(0xffF5F5F5)))
                ),
                child:Container(
                  width: setWidth(16),
                  height: setWidth(9),
                  child: Image.asset("assets/images/pay_down.png"),
                ),
              ),
            ),
            Offstage(
              offstage: keyIsShow,
              child:   Container(
                  color: Color(0xffE3E8EE),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Expanded(
                        child: Column(
                          children: [
                            Wrap(
                              children: keyboard.asMap().map((key, value){
                                return MapEntry(key, GestureDetector(
                                  onTap: (){
                                    if(passWord.length < 6){
                                      setState(() {
                                        passWord = passWord+value;
                                      });
                                    }else{
                                      toast("密码超长");
                                    }
                                  },
                                  child: Container(
                                      alignment: Alignment.center,
                                      width: setWidth(94),
                                      height:setWidth(60),
                                      decoration: BoxDecoration(
                                          color: Colors.white,
                                          border: Border(top: BorderSide(color: Color(0xffE6E7E9),width: setWidth(0.5)),right: BorderSide(color: Color(0xffE6E7E9),width: setWidth(0.5)),)
                                      ),
                                      child: Text(
                                        value,
                                        style:  TextStyle(color: Color(0xff333333), fontSize: setSp(30)),
                                      )),
                                ));
                              }).values.toList(),
                            ),
                            Row(
                              children: [
                                GestureDetector(
                                  onTap:(){
                                    if(passWord.length < 6){
                                      setState(() {
                                        passWord = passWord+"0";
                                      });
                                    }else{
                                      toast("密码超长");
                                    }
                                  },
                                  child: Container(
                                      alignment: Alignment.center,
                                      width: setWidth(188),
                                      height:setWidth(60),
                                      decoration: BoxDecoration(
                                          color: Colors.white,
                                          border: Border(top: BorderSide(color: Color(0xffE6E7E9),width: setWidth(0.5)),right: BorderSide(color: Color(0xffE6E7E9),width: setWidth(0.5)),)
                                      ),
                                      child: Text(
                                        "0",
                                        style:  TextStyle(color: Color(0xff333333), fontSize: setSp(30)),
                                      )),
                                ),
                                GestureDetector(
                                  onTap:(){
                                    if(passWord.length < 6){
                                      setState(() {
                                        passWord = passWord+".";
                                      });
                                    }else{
                                      toast("密码超长");
                                    }
                                  },
                                  child: Container(
                                      alignment: Alignment.center,
                                      width: setWidth(94),
                                      height:setWidth(60),
                                      decoration: BoxDecoration(
                                          color: Colors.white,
                                          border: Border(top: BorderSide(color: Color(0xffE6E7E9),width: setWidth(0.5)),right: BorderSide(color: Color(0xffE6E7E9),width: setWidth(0.5)),)
                                      ),
                                      child: Text(
                                        ".",
                                        style:  TextStyle(color: Color(0xff333333), fontSize: setSp(30)),
                                      )),
                                ),
                              ],
                            )
                          ],
                        ),
                      ),
                      Container(
                        width: setWidth(93),
                        child: Column(
                          children: [
                            GestureDetector(
                              onTap: (){
                                if(passWord.length > 0){
                                  setState(() {
                                    passWord =   passWord.substring(0,passWord.length-1);
                                  });
                                }else{
                                  toast("请输入密码");
                                }
                                print(passWord);
                              },
                              child: Container(
                                height: setWidth(60),
                                alignment: Alignment.center,
                                color: Colors.white,
                                child: Image.asset("assets/images/black_pay_delete.png",width: setWidth(27),height: setWidth(19),fit: BoxFit.cover,),

                              ),
                            ),
                            GestureDetector(
                              onTap: (){
                                if(passWord.length<6){
                                  toast("请输入完整密码");
                                }
                              },
                              child: Container(
                                  height: setWidth(181),
                                  alignment: Alignment.center,
                                  color: Color(0xff00C65F),
                                  child: Text(
                                    "确定",
                                    style:  TextStyle(color: Colors.white, fontSize: setSp(18)),
                                  )
                              ),
                            ),
                          ],
                        ),
                      )
                    ],
                  )
              ),
            ),
          ],
        ),
      ),
    );
  }
}
